﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PluginInterface;
using Buccontrols;
using Buccaneer;

namespace PluginTry
{
    /// <summary>
    /// PluginAction to be invoked when 'navigate([path]' is entered in the console
    /// </summary>
    public class NavigateAction : PluginAction
    {
        public NavigateAction()
        {
            // set the name of the action
            base.name = "navigate";
            // declare which function has to be invoked
            base.func = new ActionFunction(Navigate);
            // let them know one parameter is needed.
            base.pars.Add("path", "The path to navigate to");
            // just for example: add an optional param
            base.pars.Add("rememberHistory", "optional: boolean value wheter this path should be remembered or not");
        }

        public static void Navigate(string[] args)
        {
            // let everybody know we're not ready jet :P
            Options.WriteComment("(i) Navigating not implemented jet!");
        }
    }

    /// <summary>
    /// PluginAction to be invoked when 'close(' or 'close' is entered in the console
    /// </summary>
    public class CloseAction : PluginAction
    {
        public CloseAction(PluginForm client)
        {
            // set the name of the action
            base.name = "close";
            // declare which function has to be invoked
            base.func = new ActionFunction(Close);
            // add an exception-handler; when this PluginAction will be invoked form another thread, it this function will be called
            base.exceptions.Add("System.InvalidOperationException", new ActionFunction(CloseThreadSafe));
            // set which form this function is for
            base.pluginForm = client;
            // put the daddy in his cage :P
            base.pluginDaddy = client.MdiParent as PluginDaddy;
        }

        public void Close(string[] args)
        {
            // just simply close the 'client' form (see contructor)
            base.pluginForm.Close();
        }

        public void CloseThreadSafe(string[] args)
        {
            // request daddy to close his lil' child, our 'client' when he's activated
            base.pluginDaddy.ActRequest("close", args);
        }
    }
}
